package com.hay.goods.controller;

import com.hay.goods.service.GoodsHtmlService;
import com.hay.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * @title: GoodsController
 * @Author HuangYan
 * @Date: 2020/7/30 14:52
 * @Version 1.0
 */
@Controller
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private GoodsHtmlService goodsHtmlService;

    @GetMapping("item/{id}.html")
    public String getItemPage(@PathVariable("id") Long id, Model model){
        Map<String, Object> dataMap = goodsService.getItemPageData(id);
        model.addAllAttributes(dataMap);
        // 页面静态化
        goodsHtmlService.pageToStatic(id);
        return "item";
    }
}
